package cc.rengu.redp.bizimpl.upmp.controller;


import cc.rengu.redp.bizimpl.constant.UpmpConstant;
import cc.rengu.redp.bizimpl.igas.bean.InstInfo;
import cc.rengu.redp.bizimpl.igas.vo.InstInfoListQueryRespVO;
import cc.rengu.redp.bizimpl.upmp.domain.UpmpSysParam;
import cc.rengu.redp.bizimpl.upmp.service.IBViewLinkCfgService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.vo.*;
import cc.rengu.redp.common.exception.RedpException;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author System
 */
@Slf4j
@Api(tags = "可视化链路配置管理")
@RestController
@RequestMapping("/admin/viewLinkCfg")
public class BViewLinkCfgController {

    @Autowired
    private IUpmpSysParamService upmpSysParamService;

    @Autowired
    private IBViewLinkCfgService bViewLinkCfgService;

    /**
     * 获取法人行标识列表
     *
     * @return
     */
    @GetMapping("/instList")
//    @RequiresPermissions("areaInfo:view")
    public InstInfoListQueryRespVO instInfoList() {
        UpmpSysParam defaultInst = upmpSysParamService.getById(UpmpConstant.DEAFULT_INST_PARAM_ID);
        List<UpmpSysParam> sysParamList = upmpSysParamService.findChildrenByPrimaryKey(UpmpConstant.SYS_INST_PARAM, defaultInst.getInstId(), null);
        List<InstInfo> instList = Lists.newArrayList();
//        InstInfo firt = new InstInfo("", "请选择");
//        result.add(firt);
        sysParamList.forEach(inst -> {
            InstInfo instInfo = new InstInfo(inst.getPrimaryKey(), inst.getPrimaryValue());
            instList.add(instInfo);
        });
        InstInfoListQueryRespVO resp = new InstInfoListQueryRespVO();
        resp.setInstInfoList(instList);
        return resp;

    }

    /**
     * 获取服务列表及交易渠道
     *
     * @param req
     * @return
     */
    @GetMapping("/serviceAndChannelQuery")
//    @RequiresPermissions("areaInfo:view")
    public ServiceAndChannelInfoListQueryRespVO serviceAndChannelQuery(ServiceAndChannelInfoListQueryReqVO req) {
        return bViewLinkCfgService.serviceAndChannelQuery(req);
    }

    /**
     * 业务渠道交易类型查询
     *
     * @param req
     * @return
     */
    @GetMapping("/transChannelTxnQuery")
//    @RequiresPermissions("areaInfo:view")
    public TransChannelTxnInfoListQueryRespVO transChannelTxnQuery(TransChannelTxnInfoListQueryReqVO req) {
        return bViewLinkCfgService.transChannelTxnQuery(req);
    }

    /**
     * 交易链路配置查询
     *
     * @param req
     * @return
     */
    @GetMapping("/transLinkCfgInfoQuery")
//    @RequiresPermissions("areaInfo:view")
    public TransLinkCfgInfoQueryRespVO transLinkCfgInfoQuery(TransLinkCfgInfoQueryReqVO req) throws RedpException {
        return bViewLinkCfgService.transLinkCfgInfoQuery(req);
    }

    /**
     * 交易链路配置提交
     *
     * @param req
     */
    @PostMapping(value = "/transLinkCfg")
    public void transLinkCfg(@RequestBody TransLinkCfgInfoCommitReqVO req) throws RedpException {
        bViewLinkCfgService.transLinkCfg(req);
    }

    /**
     * 清分清算资金流转-获取角色账户列表
     *
     * @param req
     * @return
     */
    @GetMapping("/roleAcctQuery")
//    @RequiresPermissions("areaInfo:view")
    public RoleAcctInfoListQueryRespVO roleAcctQuery(RoleAcctInfoListQueryReqVO req) {
        return bViewLinkCfgService.roleAcctQuery(req);
    }
}
